package com.hzdesk.media.koreabatchmatvector.utils;

import android.content.Context;
import android.util.Log;

import com.hzdesk.media.koreabatchmatvector.bean.ConfigFileBean;
import com.hzdesk.media.koreabatchmatvector.bean.MeetInfoBean;
import com.hzdesk.media.koreabatchmatvector.bean.MouseUserDevicesinfoBean;
import com.hzdesk.media.koreabatchmatvector.config.AppConfig;
import com.hzdesk.media.koreabatchmatvector.dao.MeetInfoDaoUtils;
import com.hzdesk.media.koreabatchmatvector.dao.MouseUserDevicesinfoDaoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/7/4.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class DataConversionUtils {
    /**
     * @desc 将系统设置里的管理配置文件中的信息转换成 会议信息  存储数据库
     * */
    public static MeetInfoBean ConversionUtilsMeetInfo(ConfigFileBean bean, Context mContext){
        MeetInfoBean meetInfoBean = new MeetInfoBean(bean.getCreateTime(),bean.getCreator(),bean.getUpdateTime(),
                bean.getUpdator(),bean.getDelFlag(),bean.getId()+"",bean.getDeviceId(),bean.getName(),bean.getMeetName(),bean.getCurrentUse());
        MeetInfoDaoUtils meetInfoDaoUtils =   new MeetInfoDaoUtils(mContext);
        // 清除数据库并插入数据
       meetInfoDaoUtils.insertMeetInfo(meetInfoBean);
        return meetInfoBean;
    }
    /**
     * @desc 将系统设置里的管理配置文件中的信息转换成 用户鼠标信息  存储数据库
     * */
    public static void ConversionUtilsMouseUserDevicesinfo(ConfigFileBean bean, Context mContext){
        List<ConfigFileBean.DeviceMousesBean> tlist =  bean.deviceMouses;
        if(tlist != null && tlist.size() >0){
            MouseUserDevicesinfoDaoUtils mouseUserDevicesinfoDaoUtils =  new MouseUserDevicesinfoDaoUtils(mContext);
            // 先清空数据库
            mouseUserDevicesinfoDaoUtils.clear();
            for (ConfigFileBean.DeviceMousesBean deviceMousesBean : tlist) {
                    // 存储到数据库
                MouseUserDevicesinfoBean mouseUserDevicesinfoBean =  beanCarver(deviceMousesBean);
                // 向数据库插入数据
                mouseUserDevicesinfoDaoUtils.insertMouseUserDevicesinfo(mouseUserDevicesinfoBean);
            }
        }
    }

    private static MouseUserDevicesinfoBean beanCarver(ConfigFileBean.DeviceMousesBean deviceMousesBean) {
        MouseUserDevicesinfoBean mouseUserDevicesinfoBean =  new MouseUserDevicesinfoBean(deviceMousesBean.getCreateTime(),deviceMousesBean.getCreator(),
                deviceMousesBean.getUpdateTime(),deviceMousesBean.getUpdator(),deviceMousesBean.getDelFlag(),deviceMousesBean.getId(),
                deviceMousesBean.getDeviceAttId(),deviceMousesBean.getMouseNum(),deviceMousesBean.getName(),deviceMousesBean.getBrushSize(),
                deviceMousesBean.getCursorColor(),deviceMousesBean.getDisMouse(),"ff0000", AppConfig.STROKE_PEN,true);
        return mouseUserDevicesinfoBean;
    }
}
